package fzu.functiongather.CarouselPicture;

import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.Toast;

import fzu.functiongather.R;

/**
 * Created by Administrator on 2016/8/26.
 */
public class WebLoadActivity extends Activity {

    private ProgressDialog mProgressDialog;
    private ProgressBar mProgressBar;
    private WebView mWebview;
    private String url = "http://www.ilou.com.cn/AboutUs/MobilePrivacy/";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.i_activity_web_load);

        mProgressDialog = new ProgressDialog(this);
        mProgressDialog.setCancelable(true);

        mProgressBar = (ProgressBar) findViewById(R.id.pb_webview);
        mProgressBar.incrementProgressBy(1);
        mProgressBar.setVisibility(View.VISIBLE);
        mWebview = (WebView) findViewById(R.id.wv_service_item);
        mWebview.getSettings().setJavaScriptEnabled(true);//设置使用够执行JS脚本
        mWebview.getSettings().setBuiltInZoomControls(true);//设置使支持缩放
        mWebview.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
                mProgressBar.setVisibility(View.VISIBLE);
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                mProgressBar.setVisibility(View.GONE);
            }

            @Override
            public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
                super.onReceivedError(view, request, error);
                view.stopLoading();
                view.loadUrl("about:blank");
                view.loadUrl("");
                Toast.makeText(WebLoadActivity.this, "加载失败,请检查网络。", Toast.LENGTH_SHORT).show();
            }
        });
        String banner = getIntent().getStringExtra("banner");
        if(banner !=null && banner.equals("banner") ){
            url = getIntent().getStringExtra("url");
            setTitle("详情");
            mWebview.loadUrl(url);
        }else {
            setTitle("爱楼用户协议");
            mWebview.loadUrl(url);


        }


    }
}

